import { Injectable } from '@angular/core';
import {Http, Headers,RequestOptions} from "@angular/http";
import {User} from "../model/user";
import {Observable} from "rxjs";
import 'rxjs/Rx';
import {Router} from "@angular/router";
declare var $:any;

@Injectable()
export class LoginService {

  constructor(public http:Http,public router: Router){}

  public login(user:User){
     return this.http.post('/api/user/login',  {user: JSON.stringify(user)});
   /* let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
    let options = new RequestOptions({ headers: headers });*/
    /*return this.http.post('/api/user/login',  {user: JSON.stringify(user)}).map((e) => {
        let userJ = e.json();
       // let userJJ = JSON.parse(userJ.data);
        console.log({user: userJ});
        //console.log({userJJJ: userJJ.userName});
        if(userJ.status==1){
        /!*if(user && user.token){*!/
          console.log('用户登录成功');
          sessionStorage.setItem("currentUser",JSON.stringify(user));
          this.router.navigateByUrl('/reactor');
        }
        return e;
      });*/
  }

  public logout():void{
    sessionStorage.removeItem("currentUser");
  }

}
